package com.mxfcode.bbs_common.util.token;

import java.util.HashMap;
import java.util.Map;

public class ReturnVo extends HashMap<String, Object> {

	private static final long serialVersionUID = 1L;
	private static final String RESULT = "result";

	public ReturnVo() {
		put("code", 0);
		put("msg", "success");
	}

	/**
	 * 未知异常返回
	 */
	public static ReturnVo error() {
		return error(500, "未知异常，请联系管理员");
	}

	/**
	 * 未知异常返回
	 */
	public static ReturnVo sessionError() {
		return error(401, "session失效");
	}

	/**
	 * 返回异常信息
	 */
	public static ReturnVo error(String msg) {
		return error(500, msg);
	}

	/**
	 * 返回异常状态码，信息
	 */
	public static ReturnVo error(int code, String msg) {
		ReturnVo returnVo = new ReturnVo();
		returnVo.put("code", code);
		returnVo.put("msg", msg);
		return returnVo;
	}

	/**
	 * 成功信息
	 */
	public static ReturnVo ok(String msg) {
		ReturnVo returnVo = new ReturnVo();
		returnVo.put("msg", msg);
		return returnVo;
	}

	public static ReturnVo ok(Map<String, Object> map) {
		ReturnVo returnVo = new ReturnVo();
		returnVo.putAll(map);
		return returnVo;
	}

	public static ReturnVo ok() {
		return new ReturnVo();
	}

	@Override
	public ReturnVo put(String key, Object value) {
		super.put(key, value);
		return this;
	}
//	public ReturnVo serverResult(ServerEntity serverEntity) {
//		put(RESULT, serverEntity);
//		return this;
//	}
}